layui.use(['echarts', 'count'], function() {
    var $ = layui.jquery,
        count = layui.count,
        echarts = layui.echarts;

    var xLAxisList = wealthDateList;
    var dataList = wealthTotalMoneyList;
    console.log(wealthTotalMoneyList)

    var maxData = 8000;
    var minData = 7000;
    $.each(wealthTotalMoneyList, function (index, item) {
        if (item > maxData) {
            maxData = item + 100
        }
        if (item < minData) {
            minData = item -100
        }
    })
    maxData = Math.ceil(maxData/100)*100
    minData = Math.ceil(minData/100)*100

    count.up("totalMoney", {time: 3000, num: wealthTotalMoney, bit: 2, regulator: 50})
    count.up("totalDebt", {time: 3000, num: wealthTotalDebt, bit: 2, regulator: 50})
    count.up("realMoney", {time: 3000, num: wealthRealMoney, bit: 2, regulator: 50})
    count.up("debtPercentage", {time: 3000, num: wealthDebtPercentage, bit: 2, regulator: 50})

    var recordsTable = echarts.init(document.getElementById('totalMoneyRecords'), 'dark');
    var option = {
        tooltip: {show: false},
        grid: {top: '10%', bottom: '6%', left: '6%', right: '6%', containLabel: true},
        xAxis: [{
            type: 'category',
            boundaryGap: false,
            axisLine: {show: false},
            axisTick: {show: false},
            axisLabel: {margin: 10, fontSize: 14, color: 'rgba(#999)'},
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#939ab6',
                    opacity: .15
                }
            },
            data: xLAxisList
        }],
        yAxis: [{
            type: 'value',
            offset: 15,
            max: maxData,
            min: minData,
            axisTick: {show: false},
            axisLine: {show: false},
            axisLabel: {margin: 10, fontSize: 14, color: '#999'},
            splitLine: {show: false}
        }],
        series: [{
            name: '2',
            type: 'line',
            z: 3,
            showSymbol: false,
            smoothMonotone: 'x',
            lineStyle: {
                width: 3,
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0,
                        color: 'rgba(59,102,246)' // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: 'rgba(118,237,252)' // 100% 处的颜色
                    }]
                },
                shadowBlur: 4,
                shadowColor: 'rgba(69,126,247,.2)',
                shadowOffsetY: 4
            },
            areaStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0,
                        color: 'rgba(227,233,250,.3)' // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: 'rgba(248,251,252,.1)' // 100% 处的颜色
                    }]
                }
            },
            smooth: true,
            data: dataList
        }]
    };
    recordsTable.setOption(option);

    window.onresize = function() {
        recordsTable.resize();
    }


    var aChart = echarts.init(document.getElementById('a'), 'dark');
    var aData = [];
    wealthChangeList.forEach(function (item, index) {
        aData.push({"name":item.resource,"value":item.money})
    })
    var op = {
        title: {text: '', left: 'center'},
        tooltip: {trigger: 'item'},
        series: [
            {
                name: '',
                type: 'pie',
                radius: '50%',
                data: aData,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    op && aChart.setOption(op);
});